﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Application.AppConfigureManage;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BytesMapObjectInfoController : ControllerBase
    {
        private readonly ILogUtil _logger;
        private readonly BytesMapObjectInfoApp _BytesMapObjectInfoApp;
        public BytesMapObjectInfoController(ILogUtil logger, BytesMapObjectInfoApp BytesMapObjectInfoApp)
        {
            _logger = logger;
            _BytesMapObjectInfoApp = BytesMapObjectInfoApp;
        }

        [HttpPost]
        public async Task<HeaderResult<long>> AddBytesMapObjectInfoAsync(BytesMapObjectInfoDto BytesMapObjectInfoDto)
        {
            try
            {
                long result = await _BytesMapObjectInfoApp.AddBytesMapObjectInfoAsync(BytesMapObjectInfoDto);
                return ApiBase.Success(result, "新增报文解析配置成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<long>(ex.Message);
            }
        }

        [HttpGet]
        public async Task<HeaderResult<bool>> DeleteBytesMapObjectInfoAsync(long ID)
        {
            try
            {
                bool result = await _BytesMapObjectInfoApp.DeleteBytesMapObjectInfoAsync(ID);
                return ApiBase.Success<bool>("删除报文解析配置成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<bool>(ex.Message);
            }
        }

        [HttpPost]
        public async Task<HeaderResult<bool>> UpdateBytesMapObjectInfoAsync(BytesMapObjectInfoDto BytesMapObjectInfoDto)
        {
            try
            {
                bool result = await _BytesMapObjectInfoApp.UpdateBytesMapObjectInfoAsync(BytesMapObjectInfoDto);
                return ApiBase.Success<bool>("修改报文解析配置成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<bool>(ex.Message);
            }
        }

        [HttpPost]
        public async Task<HeaderResult<List<BytesMapObjectInfoDto>>> GetAllBytesMapObjectInfoAsync(QueryBytesMapObjectInfoDto queryBytesMapObjectInfoDto)
        {
            try
            {
                var pageList = await _BytesMapObjectInfoApp.GetBytesMapObjectInfoAsync(queryBytesMapObjectInfoDto);
                return ApiBase.Info(pageList.Result, pageList.Total, "查询成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<List<BytesMapObjectInfoDto>>(ex.Message);
            }
        }

        [HttpGet]
        public async Task<HeaderResult<BytesMapObjectInfoDto>> GetBytesMapObjectInfoByIDAsync(long ID)
        {
            try
            {
                var result = await _BytesMapObjectInfoApp.GetBytesMapObjectInfoByIDAsync(ID);
                return ApiBase.Success(result, "获取数据成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<BytesMapObjectInfoDto>(ex.Message);
            }
        }

    }
}
